package cn.wolfcode.wolf2w.util;

import cn.wolfcode.wolf2w.domain.Destination;
import cn.wolfcode.wolf2w.query.DestinationQueryObject;
import cn.wolfcode.wolf2w.query.QueryObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.*;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.util.StringUtils;

import java.util.List;

public class DBHelper {
    //分页工具方法
    public static  <T> Page<T> query(QueryObject qo,Query query,Class<T> clz,MongoTemplate template,Pageable pageable) {
        //3、计算total
        long count = template.count(query,clz);
        if(count==0){
            return Page.empty();
        }
        query.with(pageable);
        List<T> list = template.find(query, clz);
        //5、返回PageImpl
        return new PageImpl<>(list, pageable, count);
    }
}
